﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference name="Dimok.Web.UI.JS.JQuery.VSDoc.js" assembly="Dimok.Web.UI" />
/// <reference name="Dimok.Web.UI.JS.MSAjaxExtentions.js" assembly="Dimok.Web.UI" />
/// <reference path="../../JS/UI/Dimok.PageEvents.js" />
Type.registerNamespace("motobankcorp");
motobankcorp.PurchaseBatches = function(element) {
motobankcorp.PurchaseBatches.initializeBase(this, [element]);
}
motobankcorp.PurchaseBatches.prototype = {
  _refreshSelected: function() {
    var gridDataItem = this.get_RGE().get_activeRow() || this.get_grid().get_selectedItems()[0];
    if (gridDataItem) {
      setTimeout(Function.createDelegate(this, function() { this.get_RGE().clickGridDataItem(gridDataItem) }), 100);
      setTimeout(Function.createDelegate(this, function() { this.get_RGE().clickGridDataItem(gridDataItem) }), 100);
    }
  },
  _wireEvents: function() {
    this.get_RGE().add_rowSelected(Function.createDelegate(this, function(sender, eventArgs) {
      Dimok.FindPageEvents().raise_purchaseBatchesSelected(eventArgs);
    }));
    this.get_RGE().add_rowDeselected(Function.createDelegate(this, function(eventArgs) {
      Dimok.FindPageEvents().raise_purchaseBatchesDeselected(eventArgs);
    }));
    Dimok.FindPageEvents().add_loanInserted(Function.createDelegate(this, function(sender, eventArgs) {
      if (eventArgs.constructor == Dimok.Event.Loan && eventArgs.get_batchItemsCount() > 0) return;
      this._refreshSelected();
    }));
    Dimok.FindPageEvents().add_loanBatchInserted(Function.createDelegate(this, function() {
      this._refreshSelected();
    }));


  },
  initialize: function() {
    motobankcorp.PurchaseBatches.callBaseMethod(this, 'initialize');
    this._wireEvents();
  },
  dispose: function() {
    motobankcorp.PurchaseBatches.callBaseMethod(this, 'dispose');
  }
}
motobankcorp.PurchaseBatches.registerClass('motobankcorp.PurchaseBatches', Dimok.Table);
